<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
    {include file="project/project_tab"}
    <div style="margin-top: 20px;">
    </div>

    <form class="layui-form" id="admin">
<!--        生产线-->
        <div class="layui-form-item">
            {notempty name="$jiraProjectList"}
            <label class="layui-form-label">产品线</label>
            <div class="layui-input-inline">
                <select name="product_line" lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    {volist name="$jiraProjectList" id="jiraProject"}
                    <option value="{$jiraProject.key}" {notempty name="$info.product_line"}{eq name="$info.product_line" value="$jiraProject.key"} selected=""{/eq}{/notempty}>{$jiraProject.name}</option>
                    {/volist}
                </select>
            </div>
            {/notempty}
        </div>
<!--        是否创建jira-->
        <div class="layui-form-item">
            {empty name="$info"}
            <label class="layui-form-label">同时创建jira</label>
            <div class="layui-input-inline">
                <input id="is_create_jira" type="checkbox" checked="" name="is_create_jira" lay-skin="switch" lay-filter="is_create_jira" lay-text="ON|OFF">
            </div>
            {/empty}
            <div class="jira_id_class" {empty name="$info"}style="display: none;"{/empty}>
            <label class="layui-form-label">关联已有jira</label>
            <div class="layui-input-inline">
                <input id="jira_id" name="jira_id" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.jira_id"}value="{$info.jira_id}"{/notempty}>
            </div>
            <div class="layui-form-mid layui-word-aux">例：jira.corp.yljr.com/browse/YX-1195 填写：YX-1195</div>
            </div>
        </div>
<!--        项目名称-->
        <div class="layui-form-item">
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-inline">
                <input id="project_name" name="project_name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.project_name"}value="{$info.project_name}"{/notempty}>
            </div>
            <label class="layui-form-label">优先级</label>
            <div class="layui-input-inline">
                <select name="project_level" lay-verify="required" lay-filter="aihao">
                    <option value="">请选择</option>
                    {volist name="projectLevelMap" id="projectLevel"}
                    <option value="{$key}" {notempty name="$info.project_level"}{eq name="$info.project_level" value="$key"} selected=""{/eq}{/notempty}>{$projectLevel}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">项目类型</label>
            <div class="layui-input-inline">
                <select name="project_type" lay-verify="required" lay-filter="aihao">
                    <option value="">请选择类型</option>
                    {volist name="projetcTypeName" id="ty" key="k"}
                    <option value="{$k}" {notempty name="$info.project_type"}{eq name="$info.project_type" value="$k"} selected=""{/eq}{/notempty}>{$ty} </option>
                    {/volist}
                </select>
            </div>
            <label class="layui-form-label">当前阶段</label>
            <div class="layui-input-inline">
                <select name="current_stage" lay-verify="required" lay-filter="aihao">
                    <option value="">请选择</option>
                    {volist name="projectStageName" id="ta"}
                    <option value="{$key}" {notempty name="$info.current_stage"}{eq name="$info.current_stage" value="$key"} selected=""{/eq}{/notempty}>{$ta}</option>
                    {/volist}

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input name="begin_time" id="begin_time" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.begin_time"}value="{$info.begin_time|date='Y-m-d',###}"{/notempty}>
            </div>
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
                <input name="end_time" id="end_time"  placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.end_time"}value="{$info.end_time|date='Y-m-d',###}"{/notempty}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">预估完成时间</label>
            <div class="layui-input-inline">
                <input name="estimate_time" id="estimate_time"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.estimate_time"}value="{$info.estimate_time|date='Y-m-d',###}"{/notempty}>
            </div>
            <label class="layui-form-label">需求方</label>
            <div class="layui-input-inline">
                <input name="demand_person" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.demand_person"}value="{$info.demand_person}"{/notempty}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产品经理</label>
            <div class="layui-input-inline">
                <select name="product_manager_id" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                    {volist name="personList" id="pe"}
                    <option value="{$pe.person_id}" {notempty name="$info.product_manager_id"}{eq name="$info.product_manager_id" value="$pe.person_id"} selected=""{/eq}{/notempty}>{$pe.person_name}</option>
                    {/volist}
                </select>
            </div>
                <label class="layui-form-label">项目经理</label>
                <div class="layui-input-inline">
                    <select name="project_manager_id" lay-verify="required" lay-search="">
                        <option value="">直接选择或搜索选择</option>
                        {volist name="personList" id="pe"}
                        <option value="{$pe.person_id}" {notempty name="$info.project_manager_id"}{eq name="$info.project_manager_id" value="$pe.person_id"} selected=""{/eq}{/notempty}>{$pe.person_name}</option>
                        {/volist}
                    </select>
                </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目状态</label>
            <div class="layui-input-inline">
                <select name="project_status" lay-verify="required" lay-filter="aihao">
                    <option value="">请选择</option>
                    {foreach $projectStatusName as $sss=>$sns}
                    <option value="{$sss}" {notempty name="$info.project_status"}{eq name="$info.project_status" value="$sss"} selected=""{/eq}{/notempty}>{$sns}</option>
                    {/foreach}

                </select>
            </div>
            <label class="layui-form-label">进度</label>
            <div class="layui-input-inline">
                <input name="project_speed" lay-verify="required" placeholder="项目进度范围0--100" autocomplete="off" class="layui-input" type="text" {notempty name="$info.project_speed"}value="{$info.project_speed}"{/notempty}>

            </div>
            <div class="layui-form-mid layui-word-aux">进度范围0--100</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文档链接</label>
            <div class="layui-input-inline">
                <input name="confluence_id" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.confluence_id"}value="{$info.confluence_id}"{/notempty}>
            </div>
            <div class="layui-form-mid layui-word-aux">例：wiki.corp.yljr.com/pages/viewpage.action?pageId=15341124 填写：15341124</div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">项目描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="project_content">{notempty name="$info.project_content"}{$info.project_content}{/notempty}</textarea>
            </div>
        </div>
        {notempty name="$info"}
        <input type="hidden" name="project_id" value="{$info.project_id}">
        {/notempty}
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>

    {include file="public/foot"}
    <script>
        layui.use(['layer', 'form'], function() {
            var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
            $(window).on('load', function() {
                form.on('submit(admin)', function(data) {
                    $.ajax({
                        url:"{:url('admin/project/publish')}",
                        data:$('#admin').serialize(),
                        type:'post',
                        async: false,
                        success:function(res) {
                            if(res.code == 1) {
                                layer.alert(res.msg, function(index){
                                    location.href = res.url;
                                })
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                    return false;
                });

                //监听指定开关
                form.on('switch(is_create_jira)', function(data){

                    if (this.checked){
                        $('.jira_id_class').hide();
                    }else {
                        $('.jira_id_class').show();
                    }
                });
                $('#jira_id').on('change',function () {
                    const jira_id = $('#jira_id').val();
                    $.ajax({
                        url: "{:url('admin/project/getIssueInfo')}",
                        data: {jira_id: jira_id},
                        success: function (res) {
                            if(res.code == 1){
                                $('#project_name').val(res.data.project_name);
                            }
                            console.log(res);
                        },
                        error: function (err) {
                            console.error('error', err)
                        }
                    })
                })
            });
        });
    </script>
    <script type="application/javascript">
        var min_end_time = '',
            max_begin_time = '';
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                trigger: 'click',
                elem: '#begin_time'
                ,done: function(value, date){
                    min_end_time = value;
                    dateDestroy('end_time');
                    dateDestroy('estimate_time');
                    initEndDate();
                    initEstimateEndDate();
                }
            });
            laydate.render({
                trigger: 'click',
                elem: '#end_time'
                ,done: function(value, date){
                    max_begin_time = value;
                    dateDestroy('begin_time');
                    initBeginDate();
                }
            });
            laydate.render({
                trigger: 'click',
                elem: '#estimate_time'
                ,done: function(value, date){
                    max_begin_time = value;
                    dateDestroy('begin_time');
                    initBeginDate();
                }
            });
        });

        //初始化开始时间插件
        function initBeginDate() {
            console.info('初始化开始时间');
            const laydate = layui.laydate;
            laydate.render({
                trigger: 'click',
                elem: '#begin_time'
                ,max: max_begin_time
                ,done: function(value, date){
                    min_end_time = value;
                    console.info('最小结束时间', min_end_time);
                    dateDestroy('end_time');
                    dateDestroy('estimate_time');
                    console.info('销毁结束时间','销毁估计时间');
                    initEndDate();
                    initEstimateEndDate();
                }
            });
        }
        //初始化结束时间插件
        function initEndDate() {
            console.info('初始化结束时间');
            const laydate = layui.laydate,
            $ = layui.jquery;
            laydate.render({
                trigger: 'click',
                elem: '#end_time'
                ,min: min_end_time
                ,done: function(value, date){
                    const estimate_date = $('#estimate_time').val();
                    // max_begin_time = estimate_date && Math.min(value, estimate_date) || value;
                    max_begin_time = estimate_date && value < estimate_date ? value : estimate_date || value;
                    console.info('最大开始时间', max_begin_time);
                    dateDestroy('begin_time');
                    console.info('销毁开始时间');
                    initBeginDate();
                }
            });
        }
        //初始化预估结束时间插件
        function initEstimateEndDate() {
            console.info('初始化估计结束时间');
            const laydate = layui.laydate,
                $ = layui.jquery;
            laydate.render({
                trigger: 'click',
                elem: '#estimate_time'
                ,min: min_end_time
                ,done: function(value, date){
                    const end_date = $('#end_time').val();
                    max_begin_time = end_date && value < end_date ? value : end_date || value;
                    console.info('最大开始时间', max_begin_time);
                    dateDestroy('begin_time');
                    console.info('销毁开始时间');
                    initBeginDate();
                }
            });
        }

        //销毁时间
        function dateDestroy(id){
            var inputDate = $("#"+id).clone(true);
            $(inputDate).removeAttr("lay-key");
            $("#"+id).after(inputDate);
            $("#"+id).remove();
        }
    </script>
</div>
</body>
</html>